package arrayListExercises.saveStudentList;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author: bamboo_shoot
 * @date: 20/2/5 18:20
 * @description: 创建一个存储学生对象的集合，存储3个学生对象，使用程序实现在控制台遍历该集合
 * 学生的姓名和年龄来自于键盘录入
 */
public class RecordManually {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Student> students = new ArrayList<Student>();
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入您的姓名");
            String name = sc.nextLine();
            System.out.println("请输入您的年龄");
            String age = sc.nextLine();
            Student s = new Student(name, age);
            students.add(s);
        }
        traversal(students);
    }

    private static void traversal(ArrayList<Student> students) {
        for (Student student : students) {
            System.out.println(student.getName() + "--" + student.getAge());
        }
    }
}
